//
//  Test19.cpp
//  CPPTest
//
//  Created by you5 Yi on 2021/9/25.
//

#include "Test19.hpp"
#include <iostream>
using namespace std;

int f2(int n)
{
    if (n <= 0) {
        throw n;
    }
    int s = 1;
    for (int i=n; i>0; i--) {
        s *= i;
    }
    return s;
}

void test19()
{
    try {
        cout<<"4!="<<f2(4)<<endl;
        cout<<"-2!="<<f2(-2)<<endl;
    } catch (int n) {
        cout<<"\nn="<<n<<"不能计算n!"<<endl;
    } catch(...) {
        cout<<"出现异常！"<<endl;
    }
    cout<<"程序执行结束"<<endl;
}
